package com.xluomo.notification_listen_service_plugin;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import java.util.HashMap;

import io.flutter.plugin.common.EventChannel;

public class NotificationEventService extends BroadcastReceiver {

    private EventChannel.EventSink eventSink;

    public NotificationEventService(EventChannel.EventSink eventSink) {
        this.eventSink = eventSink;
    }

    @Override
    public void onReceive(Context context, Intent intent) {


        HashMap<String, Object> data = new HashMap<>();
        data.put("id", intent.getIntExtra(NotificationVars.ID, -1));
        data.put("packageName", intent.getStringExtra(NotificationVars.PACKAGE));
        data.put("title", intent.getStringExtra(NotificationVars.TITLE));
        data.put("content", intent.getStringExtra(NotificationVars.CONTENT));
        data.put("hasRemoved", intent.getBooleanExtra(NotificationVars.REMOVE, false));


        if (eventSink != null) {
            eventSink.success(data);
        }
    }
}
